﻿$(function () {
    $('#TopSlider').bxSlider({
        auto: true,
        autoControls: true
    });
    $('#BottomSlider').bxSlider({
        auto: true,
        autoControls: false,
        controls: false,
        pager: false,
        minSlides: 6,
        maxSlides: 6,
        slideWidth: 180,
        slideMargin: 5
    });
    //news menu
    $('#NewsMenu').hover(function () {
        $(this).find('ul:first').stop().slideDown();
    }, function () {
        $(this).find('ul:first').stop().slideUp();
    });
    $('#MedicineMenu').hover(function () {
        $(this).find('ul:first').stop().slideDown();
    }, function () {
        $(this).find('ul:first').stop().slideUp();
    });
    $('ul').each(function () {
        if ($(this).find('li').length == 0) {
            $(this).remove();
        }
    });

    //product detail:

    $('#ProductPhotoSlider').bxSlider({
        pagerCustom: '#ProductPhotoSliderPager',
        autoControls: false,
        controls: false
    });
    $('#SearchTopTxt').off('keyup').on('keyup', function (e) {
        if (e.keyCode == 13) {
            var txt = $(this).val();
            if ($.trim(txt) != '') {
                $('#SearchTopTrigger').trigger('click');
            }
        }
    });
    //top search
    $('#SearchTopTrigger').off('click').on('click', function () {
        var txt = $('#SearchTopTxt').val();
        if ($.trim(txt) != '') {
            window.location.href = '/tim-thuoc.aspx?keyword=' + txt;
        }
    });
    //search medicine
    $('#SearchMedicineKeywordTxt').off('keyup').on('keyup', function (e) {
        if (e.keyCode == 13) {
            var txt = $(this).val();
            $('#MedicineSearchTrigger').trigger('click');
        }
    });
    $('#MedicineSearchTrigger').off('click').on('click', function () {
        var keyword = $('#SearchMedicineKeywordTxt').val();
        var cats = "";
        $('#FilterByCategory input[type=checkbox]').each(function () {
            if ($(this).is(':checked')) {
                cats += $(this).val() + ";";
            }
        });
        window.location.href = '/tim-thuoc.aspx?keyword=' + keyword + '&categories=' + cats;
    });
    $('#ViewAllCategory').off('click').on('click', function () {
        if ($('#FilterByCategory').hasClass('big')) {
            $('#FilterByCategory').removeClass('big');
            $(this).text('Xem tất cả');
        } else {
            $('#FilterByCategory').addClass('big');
            $(this).text('Thu nhỏ');
        }
    });
});